Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Been facing an issue when trying to run the html file on Chrome. It keeps showing me the error "Cannot set properties of null (setting 'textcontent')"

I've tried changing the .textcontent to .innertext and then i get the error message "Cannot set properties of null (setting 'innertext')". Could it be that it's the HTML that is faulty or what because they are all showing the same error when run on chrome. What can I do please? ta

let cards = [];
let firstcard = randomNumber();
let secondcard = randomNumber();
let sum = firstcard + secondcard;
let blackjackvalue = false; // checks for blackjack value
let isalive = true; //to check if the user can play only when the game is true
let message = "";
let gamestate = document.getElementById(message); // get the gamestate
let sumEl = document.getElementById(sum); //holding the sum
let cardEl = document.getElementById("card"); //holding the card
let playerEl = document.getElementById("player"); //holding the player details
let playerdetails = {
  name: "John",
  wins: 5,
  amount: "$" + 500,
};
playerEl.innertext = playerdetails.name + playerdetails.wins + playerdetails.amount;

function randomNumber() {
  let jacknumbers = Math.floor(Math.random() * 14) + 1; //produces random numbers between 1 and 13 to be used by first and second card
  return jacknumbers;
  if (jacknumbers == 1) {
    return 11;
  } //these if conditions are for setting the ace card to either 1 or 11...not really sure
  else if (jacknumbers > 10) {
    return 10;
  } else {
    return jacknumbers;
  }
}


function start() {
  // let firstcard = randomNumber();
  // let secondcard = randomNumber();
  let cards = [firstcard, secondcard];
  let sum = [firstcard + secondcard];
  rendergamestate();
} //when this is called, it triggers the rendergamestate function
function rendergamestate() {
  card.innertext = "cards:" + " " + firstcard + " " + secondcard;
  for (i = 0; i < card.length; i += 1) {
    card.innertext += cards[i] + " ";
    //using the for loop to display the card contents
  }
  sumEl.innertext = "sum:" + " " + sum;
  if (sum <= 20) {
    message = "Do you want to draw a new card?";
    blackjackvalue = false;
  } else if (sum === 21) {
    message = "Blackjack!";
    blackjackvalue = true;
  } else {
    message = "You are out";
    isalive = false;
    blackjackvalue = false;
  }
  gamestate.innertext = message;
}
function newcard() {
  //this button is for the user to add a new card to the already existing cards
  if (isalive === true && blackjackvalue === false) {
    let thirdcard = randomNumber();
    sum += thirdcard; // sum=sum+thirdcard;
    cards.push(thirdcard);
    rendergamestate(); //calling the function to start the game
  }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!